package test02;

public class Foodie extends Thread {

    @Override
    public void run() {
        while (true) {
            synchronized (Desk.lock) {
                if (Desk.count == 0) {
                    break;
                } else {
                    if (Desk.foodflag == 0) {
                        try {
                            Desk.lock.wait();//等待过程会绑定锁,使得在唤醒时候,只会唤醒与锁绑定线程
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Desk.count--;
                        System.out.println(getName() + "还能再吃" + Desk.count + "碗饭");
                        //唤醒唤醒与锁绑定线程
                        Desk.lock.notifyAll();
                        Desk.foodflag = 0;
                    }
                }
            }
        }
    }


}

